from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

import sys

sys.path.append(r'..')
from web_base.base_page import BasePage


class DiscuzPage(BasePage):
    url = r'http://172.16.36.121/upload/'
    # 登录定位
    username_loc = (By.ID, 'ls_username')
    password_loc = (By.ID, 'ls_password')
    login_btn_loc = (By.XPATH, '//*[@id="lsform"]/div/div/table/tbody/tr[2]/td[3]/button')

    def __init__(self, driver):
        super().__init__(driver)
        self.get_url(self.url)

    def login(self, username, password):
        self.ele_clear(self.username_loc)
        self.input_ele(self.username_loc, username)
        self.ele_clear(self.password_loc)
        self.input_ele(self.password_loc, password)
        self.ele_click(self.login_btn_loc)
        sleep(3)

    def logout(self):
        pass

    def register(self):
        pass

    def read(self):
        pass

    def post(self):
        pass

    def reply(self):
        pass


if __name__ == '__main__':
    username = 'admin'
    password = 'sa'

    chrome_location = r'D:\software\Win_x64_1135105_chrome-win\chrome-win\chrome.exe'
    options = webdriver.ChromeOptions()
    options.binary_location = chrome_location
    driver = webdriver.Chrome(options=options)

    discuz_page = DiscuzPage(driver)
    discuz_page.login(username, password)

    driver.quit()
